import random
import uuid
import hashlib 
import math

def random_uuid():
    '''生成随机uuid'''
    return str(uuid.uuid4())

def random_str(randomlength=8):
    '''生成随机字符串'''
    strs = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789'
    length = len(chars) - 1
    for i in range(randomlength):
        strs += chars[random.randint(0, length)]
    return strs

def random_num(randomlength=8):
    '''生成随机数字'''
    strs = ''
    chars = '0123456789'
    length = len(chars) - 1
    for i in range(randomlength):
        strs += chars[random.randint(0, length)]
    return strs

chars = ['J', '4', 'B', 'X', 'E', 'V', 'F', 'G', 'W', 'I', 'A', 'K',
 '7', '5', 'N', 'P', 'Q', 'R', 'S', '3', 'U', '1', 'C', '2', 'T', '6', 'H', 'Y', '8', 'M', 'L', 'D'];
 
def charAtStuff(index):
    return chars[index] if index < len(chars) else chars[index - len(chars)]

# 根据ID生成指定位数的邀请码
def getRandomById(id, length):
    a = [0]*length
    for i in range(len(a)):
        pow = math.pow(len(chars), i)
        a[i] = charAtStuff(int(id/pow % len(chars)) + i)
    return ''.join(a)